﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using PacManPP.Managers;

namespace PacManPP.Objects
{

   
    abstract class IObject
    {
        public enum Directions
        {
            Up = 0,
            Right = 1,
            Down = 2,
            Left = 3
        }

        protected String spirteSheetName;      
        protected ContentManager content;
        protected SpriteBatch spriteBatch;
        protected Texture2D sprite;

        protected int Object_Size = 24;
        protected int Object_Scale = 1;
              
        protected int direction = 0;
        protected int move = 0;

        protected float timer = 0f;
        protected float interval = 100f;
        protected int currentFrame = 1;
        protected int maxFrame = 4;
        protected int startFrame = 1;
        
        protected Rectangle sourceRect;
        protected Vector2 origin;

        public Vector2 poistion = Vector2.Zero;

        public Vector2 Position
        {
            get { return poistion; }
            set 
            {
                poistion = value;
                poistion.X = poistion.X * GameManager.scale;
                poistion.Y = poistion.Y * GameManager.scale;
            }
        }
        
        
        public ContentManager Content
        {
            get { return content; }          
            set { content = value; }
        }
        
        public SpriteBatch SpriteBatch
        {
            get { return spriteBatch; }        
            set { spriteBatch = value; }
        }

        public virtual void LoadContent()
        {
            sprite = content.Load<Texture2D>(spirteSheetName);
            currentFrame = startFrame;
        }

        public virtual void UnloadContent() 
        {
            poistion = new Vector2(1000, 1000);
        
        
        }   
    
        public virtual void HandleInput(KeyboardState keyboardState)
        {

           

        }

        public virtual void Update(GameTime gameTime)
        {

            this.HandleInput(Keyboard.GetState());

            timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
           
            if (timer > interval)
            {          
                currentFrame++;           
                timer = 0f;
            }

            if (currentFrame == maxFrame)
            {
                currentFrame = startFrame;
            }

            sourceRect = new Rectangle(currentFrame * Object_Size, Object_Size * move , Object_Size, Object_Size);
            origin = new Vector2(sourceRect.Width / 2, sourceRect.Height / 2);        
        
        }


        public virtual void Draw(GameTime gameTime)
        {
            //SpriteBatch.Begin(); 
            spriteBatch.Draw(sprite, poistion, sourceRect, Color.White, 0f, origin, 1.0f, SpriteEffects.None, 0);
            //SpriteBatch.End();
        }


    }
}
